package FCRendering.sw;

import java.awt.Image;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import FCRendering.NpcBundle;
import Frame.entity.UnifyShopSayUIEntity;
import Frame.sayoptional.SayTextAndOption;
import Frame.shopSet.*;
import VWorldGameStudio.*;
import VWorldGameStudio.events.SayEvent;
import lombok.Getter;
import lombok.Setter;

import static FCRendering.FCRMaster.fcv;
import static FCRendering.FCRMaster.gameSave;


public class FCRValues {
    @Setter
    @Getter
    private int mouseX = 0, mouseY = 0;// 鼠标位置
    @Setter
    @Getter
    private int interfacenum = 0;//当前界面，原来的framenum
    @Setter
    @Getter
    private int frames = 0;//帧数，原来的ti
    @Setter
    @Getter
    private int enterBu = 0;// 鼠标进入的区域
    @Setter
    @Getter
    private int clickBu = 0;// 鼠标点击的区域
    @Setter
    @Getter
    private int playerw, playerh;
    @Setter
    @Getter
    private int infow, infoh;
    @Getter
    @Setter
    private int MMTitleCoorY;//重装机兵名字的y坐标，原来的zzjby
    @Setter
    @Getter
    private int nowWindowWidth, nowWindowHeight;//当前游戏窗口分辨率
    @Setter
    @Getter
    private int SaveMouseEnter = -1;// 鼠标进入的存档选项
    @Setter
    @Getter
    private int SaveMouseClick = -1;// 选中将要加载的存档选项
    @Setter
    @Getter
    private int SaveUploadIsOk = 0;// 存档加载进度，0为未加载，1为加载完毕
    @Setter
    @Getter
    private int OpenMenuNum = 0;// 打开的菜单
    @Setter
    @Getter
    private int ShopVendingEnterNum = 0;// 当前鼠标进入的地方
    @Setter
    @Getter
    private int ShopVendingSelectNum = 0;// 当前鼠标选中的地方
    @Setter
    @Getter
    private int PhonographEnterNum = -1;// 鼠标进入留声机的曲目编号
    @Setter
    @Getter
    private int SayMouseEnterSelectNum = -1;// 鼠标进入的选项
    @Setter
    @Getter
    private int BattleOpenMenuPlayer = -1;// 打开战斗菜单的玩家编号
    @Setter
    @Getter
    private int BattlePlayerSelectMenu = -1;// 玩家选择的菜单选项

    @Setter
    @Getter
    private int BattleExperience = 0;// 当前战斗累计经验
    @Setter
    @Getter
    private int Battlemoney = 0;// 当前战斗累计金币

    @Setter
    @Getter
    private int BattleOpenMenuMouseEnterX = -1, BattleOpenMenuMouseEnterY = -1;// 打开战斗菜单后，鼠标进入的选项提示位置
    @Setter
    @Getter
    private int BattleItemCoorX = -1, BattleItemCoorY = -1;// 战斗时攻击动画物品的坐标
    @Setter
    @Getter
    private int BattleItemCoorXX = -1, BattleItemCoorYY = -1;// 战斗时攻击动画物品的坐标计算间距
    @Setter
    @Getter
    private int BattleAnimationNum = 0;// 攻击计算的当前帧
    @Setter
    @Getter
    private int TankMenuCoorX = 0, TankMenuCoorY = 0;// 乘降菜单显示坐标
    @Setter
    @Getter
    private int TankMenuMouseEnterX = -1, TankMenuMouseEnterY = -1;// 鼠标进入选项提示坐标
    @Setter
    @Getter
    private int BattlePlayerOneSelectMonster = -1;// 玩家1选中的要攻击的对象
    @Setter
    @Getter
    private int BattlePlayerTwoSelectMonster = -1;// 玩家2选中的要攻击的对象
    @Setter
    @Getter
    private int BattlePupilOneSelectMonster = -1;// 徒弟1选中的要攻击的对象
    @Setter
    @Getter
    private int BattlePupilTwoSelectMonster = -1;// 徒弟2选中的要攻击的对象

    @Setter
    @Getter
    private int MapPngSize;// 每一个方块的尺寸
    @Setter
    @Getter
    private int CaseSelectNum = -1;//箱子>>选中拖动的物品编号
    @Setter
    @Getter
    private int KnapsackItemNum = -1;// 移动或使用的物品所在背包位置
    @Setter
    @Getter
    private int KnapsackItemType = -1;// 点的是坦克的还是人类的,1表示是人类背包的 2是坦克背包的
    @Setter
    @Getter
    private String KnapsackItemWho;//点的是谁的装备
    @Setter
    @Getter
    private String KnapsackItemName;//点的是名称
    @Setter
    @Getter
    private int TakeOffArmorType = -1;// 卸下装备类型，0武器，1帽子，2上衣，3裤子。4鞋子,原来的xiexiazhuangbeitype
    @Getter
    @Setter
    private int HouseNum = 0;//找房与创房
    @Getter
    @Setter
    private int SelectPlayer = 0;// 选中角色

    @Getter
    @Setter
    private int MessageShowNum = 600;// 消息显示时间

    public void showMessage(){
        MessageShowNum = 600;
    }

    @Getter
    @Setter
    private int SayNpcTextNum = 0;// npc当前说的话编号
    @Getter
    @Setter
    private int CurrentPlayerNum = 0;// 当前存档玩家与徒弟数量
    @Getter
    @Setter
    private int ShopLampNum = -1;// 当前灯编号
    @Getter
    @Setter
    private int ShopLuckDrawI = 30, ShopLuckDrawJ = 0, ShopLuckDrawN = 120;//售货机摇奖相关
    @Getter
    @Setter
    private int loadFileNum;//已经加载了多少
    @Getter
    @Setter
    private int BattleY = -1200;
    @Getter
    @Setter
    private int OldMusicNum;

    @Getter
    @Setter
    private volatile boolean monsterBuilding = false;//是否开始创建怪物，就是刚遇怪时的准备

    @Getter
    @Setter
    private int[][] ShopLampCoor = {{932, 561}, {1007, 616}, {1047, 616}, {1088, 616}, {1122, 580},
            {1088, 544}, {1047, 544}, {1007, 544}, {932, 561}, {890, 616}, {850, 616}, {809, 616},
            {775, 580}, {809, 544}, {850, 544}, {890, 544}};// 灯坐标
    @Getter
    @Setter
    private long LoadNum = 0;
    @Setter
    @Getter
    private double battleitempngbili;//战斗时的物品比例
    @Getter
    @Setter
    private double GameAlldataNum = 0;//需要加载的总数据量，除以100的占比数据
    @Setter
    @Getter
    private double proportion;//当前电脑分辨率与1920*1080的比列

    @Getter
    @Setter
    private boolean isOpenENMonster = true;
    @Getter
    @Setter
    private boolean ShopLuckDraw = true;//原来的shopyaojiang

    @Getter
    @Setter
    private boolean isSever = false;//是否是服务器
    @Getter
    @Setter
    private boolean isClient = false;//是否是客户端
    @Setter
    @Getter
    private boolean isOpenCase = false;// 是否打开箱子
    @Setter
    @Getter
    private boolean isMoveKnapsackItem = false;// 是否移动物品
    @Setter
    @Getter
    private boolean isOpenUseTankMenu = false;// 是否打开乘降菜单

    @Setter
    @Getter
    private boolean isOpenUseTankMenuChild = false;// 是否打开乘降子菜单

    @Setter
    @Getter
    private int clickTankMenu = 0;// 是否打开乘降子菜单
    @Setter
    @Getter
    private boolean isOpenSay = false;// 是否打开聊天
    @Setter
    @Getter
    private boolean isOpenSayShop = false;// 是否打开商店
    @Setter
    @Getter
    private boolean isShopVedingOpen = false;// 售货机是否打开,原来的shopvedingisopen
    @Setter
    @Getter
    private boolean isOpenMenu = false;// 是否打开菜单
    @Setter
    @Getter
    private boolean isOpenPhonograph = false;//是否打开留声机
    @Setter
    @Getter
    private boolean isOpenUseItem = false;//是否打开使用物品界面

    @Setter
    @Getter
    private boolean isOpenTanCheResult = false;//是否打开探测结果界面
    @Setter
    @Getter
    private FixTank selectingUseItem = null;

    @Setter
    @Getter
    private boolean isOpenMMWVIP = false; //是否打开联机薄

    @Getter
    private FunctionUseItem UseItemAShopFuntion = new FunctionUseItem();

    @Getter
    private FunctionTanCheResult TancheResult = new FunctionTanCheResult();

    @Getter
    private FunctionOpenMMVVIP MmWVipBookFuncion = new FunctionOpenMMVVIP();

    /**
     * 关闭所有弹的窗口先
     */
    public void closeAllShowWindw(){
        setOpenMenu(false);
        setOpenPhonograph(false);
        setShopVedingOpen(false);
        setOpenSayShop(false);
        setOpenSay(false);
        setSayNpcName(null);
        setSayNpcTextNum(0);
        setOpenUseItem(false);
        setOpenMMWVIP(false);
        setOpenTanCheResult(false);
        setOpenUseTankMenuChild(false);
        setOpenUseTankMenu(false);
        setOpenCase(false);// 关闭箱子
        setShowMapImg(false);
        getLookIntos().clear();
        getShowChuanzhenNames().clear();
        getShowTankChuanzhenNames().clear();
    }
    @Setter
    @Getter
    private boolean isBattle = false;// 是否开始战斗场景
    @Setter
    @Getter
    private boolean isBattleEnd = false;// 是否结束战斗场景
    @Setter
    @Getter
    private boolean isBattleReady = false;// 是否准备阶段

    @Setter
    @Getter
    private boolean isBattleHurtCount = false;// 是否启用伤害与动画计算
    @Setter
    @Getter
    private boolean isBattleOpenMenu = false;// 是否开启战斗菜单
    @Setter
    @Getter
    private boolean isBattlePlayerSelect = false;// 是否开启选择怪物的准心
    @Setter
    @Getter
    private boolean isBattleSummary = false;// 是否开启战斗总结
    @Setter
    @Getter
    private boolean isBattleDriverTank = false;// 战斗时是否驾驶坦克

    @Setter
    @Getter
    private boolean dirUp = false;//玩家上键是否按下
    @Setter
    @Getter
    private boolean dirDown = false;//玩家下键是否按下
    @Setter
    @Getter
    private boolean dirLeft = false;//玩家左键是否按下
    @Setter
    @Getter
    private boolean dirRight = false;//玩家右键是否按下
    @Setter
    @Getter
    private boolean isPlotJumpStep1 = false;//事件对话是否跳过,原来的plotisjumstep1
    @Getter
    @Setter
    private boolean isPlotNpc1SayClick = false;// 当前npc的对话是否是点击跳过
    @Getter
    @Setter
    private boolean isOpenConnect = false;// 是否打开连接
    @Getter
    @Setter
    private boolean isConnect = false;

    @Setter
    @Getter
    private String ShopVendingTip = FCRConstants.SVT_WITCH_BUY;//商店提示语
    @Getter
    @Setter
    private String SayText[];//说的话文本寄存库
    @Getter
    @Setter
    private String SayNpcName = "";// 对话的npcid
    @Setter
    @Getter
    private Vector<String> PhonographMusicName = new Vector<>();// 留声机音乐名字
    @Setter
    @Getter
    private Vector<Integer> PhonographMusicNum = new Vector<>();// 留声机音乐编号
    @Setter
    @Getter
    private Vector<SayTextAndOption> SayNpcSelectMenu = new Vector<>();// npc对话选项内容+跳转对象类型+内容

    @Setter
    @Getter
    private Vector<Integer[]> BattleMonsterCoor = new Vector<Integer[]>();// 怪物在界面显示的坐标,[x,y,w,h]

    @Getter
    @Setter
    private LinkedList<FCBattleOrder> BattleAttackOrder = new LinkedList<>();// 怪物与玩家的攻击顺序

    @Getter
    @Setter
    private LinkedList<FCBattleOrder> npcOrders = new LinkedList<>();//就是回合开始装备前，npc的操作，比如入场和退场

    @Getter
    @Setter
    private Vector<String> message = new Vector<String>();//消息

    @Getter
    private CopyOnWriteArrayList<FCPlayerBattleWrap> battleWraps = new CopyOnWriteArrayList<>();//战斗角色操作和坐标等
    @Getter
    @Setter
    private Vector<String> BattleItem = new Vector<>();// 战斗时获得的物品
    @Getter
    @Setter
    private Vector<FCMonster> BattleMonster = new Vector<FCMonster>();// 敌方数据
    @Getter
    @Setter
    private CopyOnWriteArrayList<String> npcName = new CopyOnWriteArrayList<String>();

    @Getter
    private ConcurrentHashMap<String, NpcBundle> npcBundleHashMap = new ConcurrentHashMap<>();

    @Getter
    @Setter
    public ArrayList<String> canUpTankTeamMembers = new ArrayList<>();//可以上下坦克的本机队伍人员

    @Getter
    @Setter
    public ArrayList<String> canUpTankTeamMemberChNames = new ArrayList<>();//可以上下坦克的本机队伍人员

    @Getter
    @Setter
    public ArrayList<String> curSelectTankOnMap = new ArrayList<>();//当前在地图选择的坦克的名字，用于上下坦克


    @Getter
    private FCEvent PlayingEvent = null;//当前正在进行的事件,原来的qwe

    //这里做一些处理,正在发生的event
    public void setPlayingEvent(FCEvent event){
        PlayingEvent = event;
        if(event != null && !gameSave.getFcEventHasHanppen().contains(event.getName())) {
            System.out.println("触发 "+event.getName());
            gameSave.getFcEventHasHanppen().add(event.getName());
        }
    }


    @Setter
    @Getter
    private FCEvent battleEvent = null;//当前正在战斗的剧情

    @Setter
    @Getter
    private FCBossRecord battleBossRecord = null;//当前正在战斗的boss名称

    @Getter
    @Setter //key 是 地图名称*坐标X*坐标Y
    private String otherEventKey;//对应otherEventMaps的key，触发时临时设置，结束后消除

    @Getter
    private LinkedList<String> battleSayText = new LinkedList<>();

    @Getter
    private CopyOnWriteArrayList<String> battleResultText = new CopyOnWriteArrayList<>();

    @Getter
    @Setter
    private int battleRounds = 0;//战到第几回合

    @Getter
    @Setter
    private Image BattleItemPng;//战斗时的物品图片

    @Setter
    @Getter
    private String plotiding1;// 进行中的剧情,进行中应该禁止角色行走


    @Getter
    @Setter
    private boolean showTeamRequest = false;//组队请求

    @Setter
    @Getter
    private int teamRequestWay = 0;//组队方式，你加入还是你邀请 0 是加入，1是邀请

    @Getter
    @Setter
    private int jumpactionnum = -1;//切场景动画

    @Getter
    @Setter
    private String connectIp;//联机的输入ip
    @Getter
    @Setter
    private String connectPort;//联机的端口


    @Getter
    @Setter
    private int fightSelectPlayer = 0;//战斗中选中那个人，就是在战斗menu顶部的人物名称

    @Getter
    @Setter
    //战斗界面中点了那个菜单menu功能，每一回合都要设置回-1,和查看人物后也是
    private int fightMenuBntSelect = -1;

    @Setter
    @Getter
    /**
     * 底部栏展示谁的物品，
     * 规则，战斗中点了自己谁的就显示谁的，别的玩家的点了不显示
     * 名称
     */
    private String showWhosBagItem = "";

    /**
     * 随机因子
     */
    @Getter
    private LinkedList<Float> mutilPlayRandomV = new LinkedList<>();


    @Getter
    @Setter
    private CopyOnWriteArrayList<FCPropulsion> propulsions = new CopyOnWriteArrayList<>();//牵引物，可以是坦克也可以是npc，人物等

    public FCPropulsion findPropulsionByHostId(String hostId) {
        for (FCPropulsion fc : propulsions) {
            if (fc.getPropulsionHostId().equals(hostId)) {
                return fc;
            }
        }
        return null;
    }

    public FCPropulsion findPropulsionOther() {
        for (FCPropulsion fc : propulsions) {
            if (!fc.getPropulsionHostId().equals(gameSave.HOST_UID)) {
                return fc;
            }
        }
        return null;
    }

    //每一回合都尝试
    public float[] getRandomVs() {
        float[] rets = new float[4];
        for(int i = 0; i<4;i++){
            if(mutilPlayRandomV.size() > 0){
                rets[i] = mutilPlayRandomV.pop();
            }else{
                rets[i] = 1;
                System.out.println("这随机数不够用了");
            }
        }
        return rets;
    }

    public float getSingleRandom(){
        if(mutilPlayRandomV.size() > 0){
            return mutilPlayRandomV.pop();
        }
        System.out.println("这随机数不够用了");
        return 1;
    }


    /**
     * 显示物
     */
    @Getter
    private CopyOnWriteArrayList<FCPropulsion> localPropulsions = new CopyOnWriteArrayList<>();

    /**
     * 当前展示的坦克信息的
     */
    @Getter
    @Setter
    private int showTankMenuTankIndex = 0;

    @Getter
    @Setter
    private ArrayList<String> tanknameList = new ArrayList<>();
    @Getter
    @Setter
    private ArrayList<String> tankHostList = new ArrayList<>();

    @Getter
    @Setter
    private FCTank dragBagWitchTank; //此时正在操作拖动了那个坦克的背包

    @Setter
    @Getter
    private String showingTankMenuDetail;//展示坦克界面的详细

    @Setter
    @Getter //做一个锁，强制等待对方回复才解除
    private String curTeamMenuClickPlayerHost = "";//邀请组队当前点击的人物

    @Setter
    @Getter //做一个锁，强制等待对方回复才解除
    private boolean lockClickPlayerHost = false;

    @Setter
    @Getter
    private String teamReqeuestFromWho = "";

    @Setter
    @Getter //队长的名称
    private String teamLeader = "";

    /**
     * 这个本体是否在别人的队伍中？仅限于玩家的角色使用，npc这种不需要判断这个
     */
    @Getter
    @Setter
    private boolean isInTeamLink = false;

    /**
     * 战斗中例如炮弹，道具的列表显示，
     */
    @Getter
    private CopyOnWriteArrayList<String> battleShowingList = new CopyOnWriteArrayList<>();
    @Getter
    @Setter
    private int battleShowListX = 0;
    @Getter
    @Setter
    private int battleShowListY = 0;


    //调查结果显示的
    @Getter
    private LinkedList<String> lookIntos = new LinkedList<String>();


    @Getter
    @Setter
    private String willChuangSongMapName;//将要传送的地图名称

    @Getter
    private CopyOnWriteArrayList<String> showChuanzhenNames = new CopyOnWriteArrayList<>();

    @Getter
    private CopyOnWriteArrayList<String> showTankChuanzhenNames = new CopyOnWriteArrayList<>();

    //找到这个位置有没有npc，有返回npc名称
    public String checkAndGetNpcInXYTag(String xyTag){
        Iterator<Map.Entry<String, NpcBundle>> iterator = npcBundleHashMap.entrySet().iterator();
        while (iterator.hasNext()){
            NpcBundle npcBundle = iterator.next().getValue();
            if(npcBundle != null && npcBundle.isContainXY(xyTag)){
                return npcBundle.npcName;
            }
        }
        return null;
    }


    public static void resetUnifySayUIEntity(){
        for(int i = 0; i<7;i++){
            leftWindowUI[i].reset();
            rightWindowUI[i].reset();
        }
        unifyShopSayShowImg = null;
    }

    @Getter//在右边窗固定位置画出就行了
    public static Image unifyShopSayShowImg = null;
    @Getter
    public static UnifyShopSayUIEntity[] leftWindowUI = new UnifyShopSayUIEntity[7];
    @Getter
    public static UnifyShopSayUIEntity[] rightWindowUI = new UnifyShopSayUIEntity[7];
    static {
        for(int i = 0; i<7;i++){
            leftWindowUI[i] = new UnifyShopSayUIEntity();
            rightWindowUI[i] = new UnifyShopSayUIEntity();
        }
    }

    @Getter
    @Setter
    private AShopFuntion currentAShopFuntion;


    @Setter
    @Getter
    private boolean showHelpUI = false;//打开帮助界面

    @Setter
    @Getter
    private int yuGuaiStepLimit = -1;//遇怪计步，用途是当这次遇怪了，比如再走3步才计算遇怪

    @Setter
    @Getter
    private boolean hasChangeOtherPlayerTankItem = false; //打开战车界面的时候，或者使用了战车道具的时候标记需要同步更改给主人

    @Getter
    @Setter //是否正在打开地图，要满足hasStartMapFunction
    private boolean showMapImg = false;


    public void startBattleInfo(String s){
        getBattleResultText().add(s);
    }

    public void endBattleInfo(String s){
        getBattleResultText().add(s);
    }

    //代理接口
    public Vector<String> getSaytext(SayEvent sayEvent){
        Integer curSelectNum = gameSave.getSayEventTalkSelects().get(sayEvent.getName());
        if(curSelectNum == null){
            curSelectNum = 0;
        }
        return sayEvent.getSaytextBySelectNum(curSelectNum);
    }

    //代理接口
    public String getSayTextOfNum(int num, SayEvent sayEvent) {
        Vector<String> texts = getSaytext(sayEvent);
        if (num < texts.size()) {
            return texts.get(num);
        }
        return null;
    }

    @Getter
    @Setter//设置了就会自动保存
    private boolean setAutoSave = false;

    @Getter
    @Setter //最近一次结束的对话ID
    private String lastEndSayEventId = null;
    @Getter
    @Setter //最近一次结束的对话到第几阶段
    private int lastEndSayNum = 0;

    @Getter
    @Setter //滑行方向
    private int slideDir = 0;
    @Getter
    @Setter //是否是行走还是滑动中，
    private boolean isSliding = false;
    @Getter
    @Setter
    private int slideTargetMapX = -1;//指滑到地图X
    @Getter
    @Setter
    private int slideTargetMapY = -1;//指滑到地图Y

    @Getter
    @Setter //钩住了玩家，跟随移动了
    private String bindingPlayerName = null;

    @Getter
    @Setter
    private String bindingPlayerHostId = null;



}